home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!hpl3sn03.cern.ch
- From: Dan Pop <danpop@mail.cern.ch>
- Newsgroups: comp.lang.c
- Subject: Re: simple code, argc, argv, strcmp()
- Date: Sat, 10 Feb 1996 04:09:32 +0100
- Organization: CERN European Lab for Particle Physics
- Message-ID: <9602100309.AA15971@dxmint.cern.ch>
- References: <11f7cc$17261a.3b3@daprez> <harmon.823197381@pegasus.montclair.edu>
- X-NNTP-Posting-Host: hpl3sn03.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
- X-Mail2News-Path: dxmint.cern.ch!hpl3sn03.cern.ch
-
- harmon@pegasus.montclair.edu (Derek Harmon) writes:
-
- >otisg@panther.middlebury.edu (Otis Gospodnetic) writes:
- >> if (!strcmp(argv[1],"-d") || !strcmp(argv[1],"-e")) {
- >> Usage();
- >> }
- >
- > This is where your troubles lie. Let's think for a second, if argv[1]
- >is "-d", then the first clause is false. BUT, if argv[1] is "-d" then it
- >cannot also be "-e", so the second clause is true, and Usage() is called.
- >On the other hand, if argv[1] is "-e", then the second clause is false.
- >Unfortunately, argv[1] is then surely not "-d", and the first clause is true.
- >
- > Therefore, I would suggest that you only call Usage() when argv[1] is
- >not "-d" AND not "-e":
- >
- >: if (!strcmp(argv[1],"-d") && !strcmp(argv[1],"-e")) {
-
- Yet another guy who got it wrong :-) This will evaluate to 1 only when
- argv[1] is "-d" AND "-e", i.e. NEVER.
-
- !strcmp() is EVIL and this thread demonstrated it a zillion times.
- Don't use it if you want to preserve your sanity :-)
-
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-